package com.dup.jxlh.admin.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dup.jxlh.admin.entities.handler.ContractTypeHandler;
import com.dup.jxlh.admin.entities.model.Contract;
import com.dup.jxlh.admin.entities.vo.ContractVO;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface ContractMapper extends BaseMapper<Contract> {
    @Select("select contract.* from contract ${ew.customSqlSegment}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "attachList",
                    many = @Many(select = "com.dup.jxlh.admin.mapper.ContractAttachMapper.getContractAttachList")),

            @Result(column = "type", property = "type"),
            @Result(column = "type", property = "typeName", typeHandler = ContractTypeHandler.class),

            @Result(column = "department_id", property = "departmentId"),
            @Result(column = "department_id", property = "department",
                    one = @One(select = "com.dup.jxlh.admin.mapper.DepartmentMapper.selectById")),

            @Result(column = "record_id", property = "recordId"),
            @Result(column = "record_id", property = "recorder",
                    one = @One(select = "com.dup.jxlh.admin.mapper.AdminMapper.selectById"))
    })
    ArrayList<ContractVO> getContractList(Page page, @Param(Constants.WRAPPER) Wrapper<Contract> wrapper);

    @Select("select contract.* from contract ${ew.customSqlSegment}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "attachList",
                    many = @Many(select = "com.dup.jxlh.admin.mapper.ContractAttachMapper.getContractAttachList")),

            @Result(column = "type", property = "type"),
            @Result(column = "type", property = "typeName", typeHandler = ContractTypeHandler.class),

            @Result(column = "department_id", property = "departmentId"),
            @Result(column = "department_id", property = "department",
                    one = @One(select = "com.dup.jxlh.admin.mapper.DepartmentMapper.selectById")),

            @Result(column = "record_id", property = "recordId"),
            @Result(column = "record_id", property = "recorder",
                    one = @One(select = "com.dup.jxlh.admin.mapper.AdminMapper.selectById"))
    })
    ArrayList<ContractVO> getContractData(@Param(Constants.WRAPPER) Wrapper<Contract> wrapper);

}
